home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / tagteam.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  4KB  |  207 lines

  1. /***************************************************************************
  2.  
  3.     vidhrdw.c
  4.  
  5.     Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int flipscreen = 0;
  13. static int palettebank;
  14.  
  15.  
  16.  
  17. void tagteam_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  18. {
  19.     int i;
  20.  
  21.  
  22.     for (i = 0;i < Machine->drv->total_colors;i++)
  23.     {
  24.         int bit0,bit1,bit2;
  25.  
  26.  
  27.         /* red component */
  28.         bit0 = (*color_prom >> 0) & 0x01;
  29.         bit1 = (*color_prom >> 1) & 0x01;
  30.         bit2 = (*color_prom >> 2) & 0x01;
  31.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  32.         /* green component */
  33.         bit0 = (*color_prom >> 3) & 0x01;
  34.         bit1 = (*color_prom >> 4) & 0x01;
  35.         bit2 = (*color_prom >> 5) & 0x01;
  36.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  37.         /* blue component */
  38.         bit0 = 0;
  39.         bit1 = (*color_prom >> 6) & 0x01;
  40.         bit2 = (*color_prom >> 7) & 0x01;
  41.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  42.  
  43.         color_prom++;
  44.     }
  45. }
  46.  
  47. READ_HANDLER( tagteam_mirrorvideoram_r )
  48. {
  49.     int x,y;
  50.  
  51.     /* swap x and y coordinates */
  52.     x = offset / 32;
  53.     y = offset % 32;
  54.     offset = 32 * y + x;
  55.  
  56.     return videoram_r(offset);
  57. }
  58.  
  59. READ_HANDLER( tagteam_mirrorcolorram_r )
  60. {
  61.     int x,y;
  62.  
  63.     /* swap x and y coordinates */
  64.     x = offset / 32;
  65.     y = offset % 32;
  66.     offset = 32 * y + x;
  67.  
  68.     return colorram_r(offset);
  69. }
  70.  
  71. WRITE_HANDLER( tagteam_mirrorvideoram_w )
  72. {
  73.     int x,y;
  74.  
  75.     /* swap x and y coordinates */
  76.     x = offset / 32;
  77.     y = offset % 32;
  78.     offset = 32 * y + x;
  79.  
  80.     videoram_w(offset,data);
  81. }
  82.  
  83. WRITE_HANDLER( tagteam_mirrorcolorram_w )
  84. {
  85.     int x,y;
  86.  
  87.     /* swap x and y coordinates */
  88.     x = offset / 32;
  89.     y = offset % 32;
  90.     offset = 32 * y + x;
  91.  
  92.     colorram_w(offset,data);
  93. }
  94.  
  95. WRITE_HANDLER( tagteam_control_w )
  96. {
  97. logerror("%04x: control = %02x\n",cpu_get_pc(),data);
  98.  
  99.     /* bit 7 is the palette bank */
  100.     palettebank = (data & 0x80) >> 7;
  101. }
  102.  
  103.  
  104. /***************************************************************************
  105.  
  106. Draw the game screen in the given osd_bitmap.
  107. Do NOT call osd_update_display() from this function, it will be called by
  108. the main emulation engine.
  109.  
  110. ***************************************************************************/
  111. static void drawchars(struct osd_bitmap *bitmap,int color)
  112. {
  113.     int offs;
  114.  
  115.  
  116.     /* for every character in the Video RAM, check if it has been modified */
  117.     /* since last time and update it accordingly. If the background is on, */
  118.     /* draw characters as sprites */
  119.  
  120.  
  121.     for (offs = videoram_size - 1;offs >= 0;offs--)
  122.     {
  123.         int sx,sy;
  124.  
  125.         if (dirtybuffer[offs])
  126.         {
  127.             dirtybuffer[offs] = 0;
  128.  
  129.             sx = 31 - offs % 32;
  130.             sy = offs / 32;
  131.  
  132.             if (flipscreen)
  133.             {
  134.                 sx = 31 - sx;
  135.                 sy = 31 - sy;
  136.             }
  137.  
  138.             /*Someday when the proms are properly figured out, we can remove
  139.             the color hack*/
  140.             drawgfx(tmpbitmap,Machine->gfx[0],
  141.                     videoram[offs] + 256 * colorram[offs],
  142.                     2*color,    /* guess */
  143.                     flipscreen,flipscreen,
  144.                     8*sx,8*sy,
  145.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  146.         }
  147.     }
  148.  
  149.     /* copy the temporary bitmap to the screen */
  150.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  151. }
  152.  
  153. static void drawsprites(struct osd_bitmap *bitmap,int color)
  154. {
  155.     int offs;
  156.  
  157.     /* Draw the sprites */
  158.     for (offs = 0;offs < 0x20;offs += 4)
  159.     {
  160.         int sx,sy,flipx,flipy;
  161.         int spritebank;
  162.  
  163.         if (!(videoram[offs + 0] & 0x01)) continue;
  164.  
  165.         sx = 240 - videoram[offs + 3];
  166.         sy = 240 - videoram[offs + 2];
  167.  
  168.         flipx = videoram[offs + 0] & 0x04;
  169.         flipy = videoram[offs + 0] & 0x02;
  170.         spritebank = (videoram[offs] & 0x30) << 4;
  171.  
  172.         if (flipscreen)
  173.         {
  174.             sx = 240 - sx;
  175.             sy = 240 - sy;
  176.  
  177.             flipx = !flipx;
  178.             flipy = !flipy;
  179.         }
  180.  
  181.         drawgfx(bitmap,Machine->gfx[1],
  182.                 videoram[offs + 1] + 256 * spritebank,
  183.                 1+2*color,    /* guess */
  184.                 flipx,flipy,
  185.                 sx,sy,
  186.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  187.  
  188.         sy += (flipscreen ? -256 : 256);
  189.  
  190.         // Wrap around
  191.         drawgfx(bitmap,Machine->gfx[1],
  192.                 videoram[offs + 0x20] + 256 * spritebank,
  193.                 color,
  194.                 flipx,flipy,
  195.                 sx,sy,
  196.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  197.     }
  198. }
  199.  
  200. void tagteam_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  201. {
  202.     drawchars(bitmap,palettebank);
  203.  
  204.     drawsprites(bitmap,palettebank);
  205. }
  206.  
  207.